package cn.snow.iot.module.warning.controller.admin.action;


import cn.snow.iot.framework.common.pojo.CommonResult;
import cn.snow.iot.module.warning.controller.admin.action.vo.WarningActionPageVO;
import cn.snow.iot.module.warning.controller.admin.action.vo.WarningActionSaveOrUpdateVO;
import cn.snow.iot.module.warning.dal.dataobject.action.WarningActionDO;
import cn.snow.iot.module.warning.service.action.IWarningActionService;
import cn.snow.iot.module.warning.utils.StringToList;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Tag(name = "管理后台 - 告警动作")
@RestController
@RequestMapping("/warning/action")
public class WarningActionController {

    @Resource
    private IWarningActionService actionService;


    /**
     * 新增或修改
     * @param action
     * @return
     */
    @PostMapping("submit")
    @ApiOperationSupport(order = 1)
    @Operation(summary = "新增或修改")
    public CommonResult submit(@RequestBody WarningActionSaveOrUpdateVO action) {
        return actionService.saveUpdate(action);
    }

    /**
     * 分页
     * @param actionPage
     * @return
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 2)
    @Operation(summary = "分页")
    public CommonResult<IPage<WarningActionDO>> page(WarningActionPageVO actionPage) {
        IPage<WarningActionDO> page = actionService.selectWarningPage(actionPage);
        return CommonResult.success(page);
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 3)
    @Operation(summary = "详情")
    public CommonResult detail (Long id) {
        return actionService.getActionById(id);
    }

    /**
     * 逻辑删除
     * @param ids
     * @return
     */
    @GetMapping("/remove")
    @ApiOperationSupport(order = 4)
    public CommonResult<Boolean> remove(@RequestParam String ids) {
        return CommonResult.success(actionService.removeAction(StringToList.toLongList(ids)));
    }

}
